public class DCLSingleton {
    private static volatile DCLSingleton instance;

    private DCLSingleton() {
    }

    // 外层if判断是否初始化
    // synchronized阻塞其他线程
    // 内层if再次判断可以防止被阻塞线程执行时覆盖已初始化的对象
    public static DCLSingleton getInstance() {
        if (instance == null) {
            synchronized (DCLSingleton.class) {
                if (instance == null) {
                    instance = new DCLSingleton();
                }
            }
        }
        return instance;
    }
}
